<template>
    <div id="friend-merchant-manage" class="w-h-100 pos-r flex-1 apply-container" style="box-sizing: border-box;overflow:hidden;">
        <div class="w-h-100 ver-flex pos-a" style="box-sizing: border-box; padding: 6px;">
            <div class="search-s page-public-s" style="box-sizing: border-box;">
                <el-card shadow="never" :body-style="{ paddingBottom: '0' }">
                    <el-form class="box-f" ref="queryForm" :inline="true">
                        <el-form-item label="选择搜索方式：">
                            <el-select 
                                v-model="searchVal" 
                                filterable 
                                class="m-2" 
                                placeholder="请选择搜索方式" 
                                @change="searchChange"
                                popper-class="set-select"
                                :popper-append-to-body="false"
                            >
                                <el-option
                                    v-for="item in searchOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <template v-if="searchVal === '1'">
                                <el-input v-model="transferVal" placeholder="请输入课程类型" />
                            </template>
                            
                            <template v-else-if="searchVal === '2'">
                                <el-input v-model="transferVal" placeholder="请选择培训时间" />
                            </template>
                            
                            <template v-else>
                                <el-select 
                                    v-model="transferVal" 
                                    filterable 
                                    class="m-2" 
                                    placeholder="是否有效" 
                                    @change="acquireChange"
                                    value-key="id"
                                    popper-class="set-select"
                                    :popper-append-to-body="false"
                                >
                                    <el-option
                                        v-for="item in responsiblePle"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </template>
                        </el-form-item>
                        <el-form-item >
                            <el-button @click='searchClick' icon="ele-Search" type="primary"> 查询 </el-button>
                            <el-button  @click="resetClick" icon="ele-Refresh"> 重置 </el-button>
                            <!-- <el-button @click="nodeClick('','add')" icon="ele-Plus" type="primary"> 新增 </el-button> -->
                        </el-form-item>
                    </el-form>
                </el-card>
            </div>

            <div style="box-sizing: border-box;" class="flex-1 pos-r">
                <div class="pos-a w-h-100" style="box-sizing: border-box;">
                    <el-card class="box-card w-h-100" shadow="never" style="margin-top: 16px;">
                        <div style="" class="w-h-100 ver-flex">
                            <div class="flex-1 pos-r">
                                <div class="pos-a w-h-100">
                                    <el-table :data="list" class="w-h-100" style="width: 100%" border v-loading="loading" element-loading-background="rgba(0, 0, 0, 0.5)">
                                        <el-table-column type="index" label="序号" width="55" :show-overflow-tooltip="true" align="center" :index="indexMethod" />
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="v_CourseName" label="课程名称"  align="center" />
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="v_SysUserName" label="用户名称"  align="center" />
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="n_FullScore" label="试卷总分"  align="center" />
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="n_Score" label="考试得分"  align="center" />
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="v_ScopeStageName" label="分数等级"  align="center" />
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="d_StartTime" label="考试开始时间"  align="center" />
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="d_EndTime" label="考试结束时间"  align="center" />
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="n_UsedTime"  label="考试用时" align="center" />
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" label="试卷状态"  align="center">
                                            <template #default="scope">
                                                <span v-if="scope.row.n_State === 0" style="color:#E6A23C;">{{scope.row.v_StateName}}</span>
                                                <span v-if="scope.row.n_State === 1" style="color:#67C23A;">{{scope.row.v_StateName}}</span>
                                                <span v-if="scope.row.n_State === 2" style="color:#F56C6C;">{{scope.row.v_StateName}}</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column min-width="180" label="操作" align="center" fixed="right">
                                            <template #default="scope">
                                                <div class="operate-s">
                                                    <el-button v-if="scope.row.n_State !== 0" @click="nodeClick(scope.row,'edit')" class="icon-e" icon="ele-Edit" size="small" text type="primary">重新考试</el-button>
                                                    <el-button v-else disabled class="icon-e" icon="ele-Edit" size="small" text type="primary">考试进行中</el-button>
                                                </div>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </div>
                            </div>
                            <div style="height: 30px;margin-top: 20px;" class="hr-flex-start">
								<el-pagination
									v-model:currentPage="pageNo"
									v-model:page-size="pageSize"
									:total="totalRows"
									:page-sizes="[10, 20, 50, 100]"
									small
									background
									@size-change="handleSizeChange"
									@current-change="handleCurrentChange"
									layout="total, sizes, prev, pager, next, jumper"
									class="w-h-100"
								/>
							</div>
                        </div>
                    </el-card>
                </div>
            </div>
        </div>
        <AddEditExaminationPaper
            :repairInfo="repairInfo"
            :isUseDialog="isUseDialog"
            @cancelUseClick="cancelUseClick"
            @controlUseClick="controlUseClick"
        />
    </div>
</template>
<script lang="ts">
import { defineComponent, ref, Ref, onMounted , reactive , toRaw } from 'vue';
import getTableData from '/@/utils/getTableData';
import { OmsEduExamOLPage } from '/@/api/centerControl/sms';
import AddEditExaminationPaper from '../component/sms/add-edit-ExaminationPaper.vue';
import { ElMessageBox , ElMessage } from 'element-plus';
// import useCurrentInstance from '/@/utils/hook/useCurrentInstance';

export default defineComponent( {
    name: 'OnlineTest',
    components: {
        AddEditExaminationPaper,
    },
    setup(props){
        const isUseDialog = ref() // 新增/编辑弹出框隐藏/显示
        const repairInfo = ref() // 传递子组件数据
        const searchVal = ref('1')
        const transferVal = ref() // 需要查询的值
        const projectNam = ref() // 友商名称数据
        let searchName = '1'
        let searchObj:any = reactive({})
        const aModel:Ref = ref(null)

        /*** 截取日期格式方法 */
        const otherData = (row:any, column:any) => {
          // 获取单元格数据
          let data = row[column.property]
          if(data == null) {
            return '-'
          }else{
            return data
          }
        };

        /*** 截取日期格式方法 */
        const formatDate = (row:any, column:any) => {
          // 获取单元格数据
          let data = row[column.property]
          if(data == null) {
              return null
          }
          let dt = new Date(data)
          let month = (dt.getMonth() + 1) < 10 ? '0' + (dt.getMonth() + 1) : (dt.getMonth() + 1)
          let date = dt.getDate() < 10 ? '0' + dt.getDate() : dt.getDate()
          return dt.getFullYear() + '-' + month + '-' + date
        };

        /*** resetFun */
        const resetFun = () => {
            let newObj = Object.keys(searchObj)
            if(newObj.length !== 0){
                newObj.map((i:any) => {
                    searchObj[i] = ''
                })
            }
        };

        /*** 搜索类型选择事件 searchChange */
        const searchChange = (val:any) => {
            searchName = val
            transferVal.value = ''
        };

        /*** acquireChange 搜索下拉框选择的数据 ---- 传给接口数据 */
        const acquireChange = (val:any) => {
            console.log(val)
        };

        /*** searchClick 查询按钮 */
        const searchClick = () => {
            resetFun()
            if(searchName === '1'){ searchObj.v_ProvideName = transferVal.value }
            if(searchName === '2'){ searchObj.v_BlamePersonnel = transferVal.value }
            if(searchName === '3'){ searchObj.n_isValid = transferVal.value }
        };

        /*** resetClick 重置按钮 */
        const resetClick = () => {
            searchVal.value = '1'
            transferVal.value = ''
            resetFun()
        };

        /*** nodeClick 新增/编辑点击事件 */
        const nodeClick = (val:string | object , am:string) => {
            val !== '' ? repairInfo.value = JSON.stringify(toRaw(val)) : repairInfo.value = ''
            isUseDialog.value = true
        };

        /*** deleteHandle 删除数据事件 */
        const deleteHandle = async (val: String | Number) => {
            ElMessageBox.confirm('请确定删除此条数据？','提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                }
            )
            .then(async() => {
                let param = {n_Id : val}
                return
                // try {
                //     let res:any = await ProviderDelete(param)
                //     if(res.success){
                //         updateFun()
                //     }
                // } catch (err) { return }
            })
            .catch(() => {
                ElMessage({
                    type: 'info',
                    message: '已取消',
                })
            })
        };

        /*** cancelUseClick 取消事件 */
        const cancelUseClick = () => {
            isUseDialog.value = false
        };

        /*** controlUseClick 提交事件 */
        const controlUseClick = () => {
            isUseDialog.value = false
        };

        /*** onSuccess 文件上传成功时的钩子函数 */
        const onSuccess = (item:any) => {
            console.log(item,'item')
        };

        onMounted(() => {});

        return {
            ...getTableData(OmsEduExamOLPage,{},searchObj),
            isUseDialog,
            cancelUseClick,
            controlUseClick,
            nodeClick,
            repairInfo,
            deleteHandle,
            resetClick,
            searchClick,
            onSuccess,
            aModel,

            searchOptions: [{
                value: '1',
                label: '课程类型'
            }, {
                value: '2',
                label: '计划培训时间'
            }, {
                value: '3',
                label: '培训是否有效'
            }], // 搜索方式
            searchVal,
            searchChange,
            transferVal,
            acquireChange,
            projectNam,
            responsiblePle: [
                {label: '有效' , value: 1},
                {label: '无效' , value: 2},
            ],
            otherData,
        }
    },
} )
</script>
<style lang="scss"> @import '../style/public.scss'; </style>
<style scoped lang="scss">
    #friend-merchant-manage {
        .box-f{
            :deep(.el-form-item__label){
                padding: 0;
            }
        }
        :deep(.el-card__body) {
            height: 100%;
        }
        :deep(.el-card){
            border: none !important;
        }
        .upload-demo{
            margin-left: 12px;
            margin-top: 2px;
        }
        ul {

            list-style: none;

            li {
                cursor: pointer;

                &:hover {
                    color: red;
                }
            }
        }
        .icon-e{
            :deep(.el-icon){
                margin-right: 0px!important;
            }
        }
    }
</style>